package and.example.addresscontacts;

import and.example.interfaces.IArguments;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;

public class SendEmailActivity extends Activity implements IArguments{

	EditText sub;
	EditText mess;
	EditText mailTo;
	String textTo;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.send_mail);
		
		sub=(EditText)findViewById(R.id.editTextSubject);
		mess=(EditText)findViewById(R.id.editTextMessage);
		mailTo=(EditText)findViewById(R.id.editTextTo);
		
		textTo= getIntent().getStringExtra(COLUMNS[4]);
		if (textTo==null) {
			textTo="Please enter an email here!";
		}
		
		mailTo.setText(textTo);
		
		RelativeLayout layout = (RelativeLayout)findViewById(R.id.header_layout);
		Button btn = (Button)layout.findViewById(R.id.header_right_btn);
		btn.setOnClickListener(new android.view.View.OnClickListener() {
			@Override
			public void onClick(View v) {
				SendEmailActivity.this.finish();
			}
		});
	}
	
	public void onclick(View v) {
		
		String subject = sub.getText().toString();
		String message = mess.getText().toString();
		
		Intent email = new Intent(Intent.ACTION_SEND);
		email.putExtra(Intent.EXTRA_EMAIL, new String[]{textTo});
		email.putExtra(Intent.EXTRA_SUBJECT, subject);
		email.putExtra(Intent.EXTRA_TEXT, message);
		
		email.setType("message/rfc822");
		startActivity(Intent.createChooser(email, "Please choose an email service"));
	}
	
}
